package com.rfid.service;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;

import com.rfid.service.exception.ClientException;

public class RFIDSynchronismInfoService {

	private static final Logger log = Logger.getLogger(RFIDSynchronismInfoService.class);
	
	public boolean isEquals(Object object, Object obj, String[] fieldNames) {
		
		for(int i = 0 ; i < fieldNames.length; i ++) {
			String methodName = "get" + fieldNames[i].toUpperCase().substring(0, 1) + fieldNames[i].substring(1);
			try {
				Method method = obj.getClass().getMethod(methodName);
				Object value = method.invoke(obj, new Object[]{});
				if(value == null) return false;
				if(!value.equals(method.invoke(object, new Object[]{}))){
					return false;
				}
			} catch (Exception e) {
				log.error(e);
				throw new ClientException(e);
			}
		}
		return true;
	}
	
}
